﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace FRW.extensions
{
    public static class IOExtension
    {
        public static FileInfo NewPath(this FileInfo fi, string oldPath, string newPath, string newPathOffset)
        {
            string newUpdatedPath = newPath + newPathOffset;

            return NewPath(fi, oldPath, newUpdatedPath);
        }

        public static FileInfo NewPath(this FileInfo fi, string oldPath, string newPath)
        {
            FileInfo nfi;

            string newFile = Regex.Replace(fi.FullName, Regex.Escape(oldPath), Regex.Escape(newPath));
            nfi = new FileInfo(newFile);

            return nfi;
        }

        public static DirectoryInfo NewPath(this DirectoryInfo di, string oldPath, string newPath, string newPathOffset)
        {
            string newUpdatedPath = newPath + newPathOffset;

            return NewPath(di, oldPath, newUpdatedPath);
        }

        public static DirectoryInfo NewPath(this DirectoryInfo di, string oldPath, string newPath)
        {
            DirectoryInfo ndi;

            string newDirectory = Regex.Replace(di.FullName, Regex.Escape(oldPath), Regex.Escape(newPath));
            ndi = new DirectoryInfo(newDirectory);

            return ndi;
        }
    }
}